<?php

class Forms_Login extends Zend_Form
{
    
    /*  
         * ======================================================================================
         * 
         * ALL the Zend_Forms classes performed by Jean Carlo Machado has the following scope:
         * 
         * public function init(); 
         * public function showForm($name,$destinationUrl);
         * 
         * The first one serves only to zend authenticate the fom         * 
         * The second one serves to show the form without use Zend patters
         * of forms. 
         * 
         * =======================================================================================
         * To call on the controllers or helpers scope:
         * 
         *      To show:
         *              require_once APPLICATION_PATH . '/forms/Forms_CriarNodo.php';
                        $form = new Forms_CriarNodo();
                        $form->setAction($this->_helper->url('recivecreatenod'));
                        $form->showForm('create','/nodo/recivecreatenod');
         * 
         *      To pick back (IN THE ACTION PASSED TO SHOW FORM):
         *                  require_once APPLICATION_PATH . '/forms/Forms_CriarNodo.php';
                            $form = new Forms_CriarNodo();

                            if($this->getRequest()->isPost())
                            {
                                $data = $this->_request->getPost();

                                print_r($data);

                                if($form->isValid($data))
                                {
                                   //DO SOMETHING
                                }
                                else
                                {
                                     $this->view->message = 'Dados Invalidos';
                                }
         * =========================================================================================
         * 
         */
    
    public function init()
    {
        /* 
         * THE FIELDS ARE THE FOLLOWING:
         * email (text)   
         * password (password)
         */
        $this->setMethod('POST');
        
        $action = new Zend_Form_Element_Hidden('action','login');
        
        $email = $this->createElement('text','email',null);
        $email->setRequired(TRUE);
        
        $password = $this->createElement('password','password',null);
        $password->setRequired(TRUE);
        
        
        $this->addElement($action);
        $this->addElement($email);
        $this->addElement($password);
        $this->addElement('submit','send',null);
    }
    
    public function showForm($name,$destinationUrl)
    {
        $return = "<form name='$name' method='post' action='$destinationUrl'";
        $return.= "<input type='hidden' name='action' value='login'>";
        $return.= "E-Mail: <input type='text' name='email' value=''><br>";
        $return.= "Senha: <input type='password' name='password' value=''><br>";
        $return.= "<input type='submit' name='send' value='Entrar'>";
        $return.= "</form>";      
        
        echo $return;
    }
}

?>
